<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="88px">
      <!--      <el-form-item label="项目ID" prop="projectId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.projectId"-->
      <!--          placeholder="请输入项目ID"-->
      <!--          clearable-->
      <!--          @keyup.enter="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="订单编号" prop="orderCode">
        <el-input v-model="queryParams.orderCode" placeholder="请输入订单编号" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="订单日期" prop="orderDate" style="width: 230px">
        <el-date-picker clearable v-model="queryParams.orderDate" type="date" value-format="YYYY-MM-DD"
          placeholder="请选择订单日期">
        </el-date-picker>
      </el-form-item>
      <!--      <el-form-item label="订单到货日" prop="requestedDeliveryDate">-->
      <!--        <el-date-picker clearable-->
      <!--          v-model="queryParams.requestedDeliveryDate"-->
      <!--          type="date"-->
      <!--          value-format="YYYY-MM-DD"-->
      <!--          placeholder="请选择订单到货日">-->
      <!--        </el-date-picker>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="到货日回复" prop="repliedDeliveryDate">-->
      <!--        <el-date-picker clearable-->
      <!--          v-model="queryParams.repliedDeliveryDate"-->
      <!--          type="date"-->
      <!--          value-format="YYYY-MM-DD"-->
      <!--          placeholder="请选择到货日回复">-->
      <!--        </el-date-picker>-->
      <!--      </el-form-item>-->
      <el-form-item label="支付状态" prop="paymentStatus" style="width: 264.4px">
        <el-select v-model="queryParams.paymentStatus" placeholder="请选择支付状态" clearable>
          <el-option v-for="dict in scm_payment_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="primary"-->
      <!--          plain-->
      <!--          icon="Plus"-->
      <!--          @click="handleAdd"-->
      <!--          v-hasPermi="['scm:scmCustomerOrders:add']"-->
      <!--        >新增</el-button>-->
      <!--      </el-col>-->
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="success"-->
      <!--          plain-->
      <!--          icon="Edit"-->
      <!--          :disabled="single"-->
      <!--          @click="handleUpdate"-->
      <!--          v-hasPermi="['scm:scmCustomerOrders:edit']"-->
      <!--        >修改</el-button>-->
      <!--      </el-col>-->
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="danger"-->
      <!--          plain-->
      <!--          icon="Delete"-->
      <!--          :disabled="multiple"-->
      <!--          @click="handleDelete"-->
      <!--          v-hasPermi="['scm:scmCustomerOrders:remove']"-->
      <!--        >删除</el-button>-->
      <!--      </el-col>-->
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="warning"-->
      <!--          plain-->
      <!--          icon="Download"-->
      <!--          @click="handleExport"-->
      <!--          v-hasPermi="['scm:scmCustomerOrders:export']"-->
      <!--        >导出</el-button>-->
      <!--      </el-col>-->
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="scmCustomerOrdersList" @selection-change="handleSelectionChange"
      @expand-change="handleExpandChange" :expand-row-keys="expandRowKeys" row-key="id">
      <!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column type="expand">
        <template #default="props">
          <el-tabs v-model="activeTabName" @tab-change="handleTabChange(props.row)">
            <el-tab-pane label="收款明细" name="receivables">
              <el-table :data="receivablesData[props.row.id] || []" v-loading="receivablesLoading[props.row.id]">
                <el-table-column label="收款日期" prop="returnDate" width="120">
                  <template #default="scope">
                    <span>{{ parseTime(scope.row.returnDate, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="收款金额" prop="money" width="120" align="right">
                  <template #default="scope">
                    <span>{{ parseFloat(scope.row.money || 0).toFixed(2) }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="收款方式" prop="payType" width="120">
                  <template #default="scope">
                    <dict-tag :options="scm_pay_type" :value="scope.row.payType" />
                  </template>
                </el-table-column>
                <el-table-column label="备注" prop="remark" />
                <el-table-column label="创建时间" prop="createTime" width="160">
                  <template #default="scope">
                    <span>{{ parseTime(scope.row.createTime) }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="操作" width="120" fixed="right">
                  <template #default="scope">
                    <el-button link type="primary" size="small"
                      @click="handleUpdateReceivables(scope.row)">修改</el-button>
                    <el-button link type="primary" size="small"
                      @click="handleDeleteReceivables(scope.row)">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
            <el-tab-pane label="发票明细" name="invoice">
              <el-table :data="invoiceData[props.row.id] || []" v-loading="invoiceLoading[props.row.id]">
                <el-table-column label="发票类型" prop="invoiceType" width="120">
                  <template #default="scope">
                    <dict-tag :options="scm_invoice_type" :value="scope.row.invoiceType" />
                  </template>
                </el-table-column>
                <el-table-column label="税前金额" prop="moneyIncludeTax" width="120" align="right">
                  <template #default="scope">
                    <span>{{ parseFloat(scope.row.moneyIncludeTax || 0).toFixed(2) }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="税率(%)" prop="taxRate" width="100" align="right">
                  <template #default="scope">
                    <span>{{ parseFloat(scope.row.taxRate || 0).toFixed(2) }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="税收金额" prop="moneyOfTax" width="120" align="right">
                  <template #default="scope">
                    <span>{{ parseFloat(scope.row.moneyOfTax || 0).toFixed(2) }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="税后金额" prop="moneyExcludeTax" width="120" align="right">
                  <template #default="scope">
                    <span>{{ parseFloat(scope.row.moneyExcludeTax || 0).toFixed(2) }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="备注" prop="remarks" />
                <el-table-column label="发票日期" prop="invoiceDate" width="160">
                  <template #default="scope">
                    <span>{{ parseTime(scope.row.invoiceDate, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="创建时间" prop="createTime" width="160">
                  <template #default="scope">
                    <span>{{ parseTime(scope.row.createTime) }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="操作" width="120" fixed="right">
                  <template #default="scope">
                    <el-button link type="primary" size="small" @click="handleUpdateInvoice(scope.row)">修改</el-button>
                    <el-button link type="primary" size="small" @click="handleDeleteInvoice(scope.row)">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
          </el-tabs>
        </template>
      </el-table-column>
      <!--      <el-table-column label="" align="center" prop="id" />-->
      <!--      <el-table-column label="项目ID" align="center" prop="projectId" />-->
      <el-table-column label="订单编号" align="center" prop="orderCode" width="180">
        <template #default="scope">
          <el-button link type="primary" @click="handleOrderCodeClick(scope.row)">
            {{ scope.row.orderCode }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="订单日期" align="center" prop="orderDate" width="120">
        <template #default="scope">
          <span>{{ parseTime(scope.row.orderDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="订单到货日" align="center" prop="requestedDeliveryDate" width="120">-->
      <!--        <template #default="scope">-->
      <!--          <span>{{ parseTime(scope.row.requestedDeliveryDate, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="到货日回复" align="center" prop="repliedDeliveryDate" width="180">-->
      <!--        <template #default="scope">-->
      <!--          <span>{{ parseTime(scope.row.repliedDeliveryDate, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="订单总金额" align="right" prop="totalAmount" width="90">
        <template #default="scope">
          <span>{{ parseFloat(scope.row.totalAmount || 0).toFixed(2) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="已收款金额" align="right" prop="receivedAmount" width="90">
        <template #default="scope">
          <span>{{ parseFloat(scope.row.receivedAmount || 0).toFixed(2) }}</span>
        </template>
      </el-table-column>
      <!-- 添加:发票金额列-->
      <el-table-column label="发票金额" align="right" prop="invoiceAmount" width="90">
        <template #default="scope">
          <span>{{ parseFloat(scope.row.invoiceAmount || 0).toFixed(2) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付状态" align="center" prop="paymentStatus" width="80">
        <template #default="scope">
          <dict-tag :options="scm_payment_status" :value="scope.row.paymentStatus" />
        </template>
      </el-table-column>
      <el-table-column label="甲方抬头" align="left" prop="buyerTitle" />
      <!--      <el-table-column label="甲方地址" align="center" prop="buyerAddress" />-->
      <!--      <el-table-column label="甲方联系人" align="center" prop="buyerPerson" />-->
      <!--      <el-table-column label="甲方电话" align="center" prop="buyerPhone" />-->
      <!--      <el-table-column label="甲方开户银行" align="center" prop="buyerAccountBank" />-->
      <!--      <el-table-column label="甲方银行账号" align="center" prop="buyerAccountNumber" />-->
      <!--      <el-table-column label="甲方签署日期" align="center" prop="buyerSignDate" width="180">-->
      <!--        <template #default="scope">-->
      <!--          <span>{{ parseTime(scope.row.buyerSignDate, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="乙方抬头" align="center" prop="sellerTitle" />-->
      <!--      <el-table-column label="乙方地址" align="center" prop="sellerAddress" />-->
      <!--      <el-table-column label="乙方联系人" align="center" prop="sellerPerson" />-->
      <!--      <el-table-column label="乙方电话" align="center" prop="sellerPhone" />-->
      <!--      <el-table-column label="乙方开户银行" align="center" prop="sellerAccountBank" />-->
      <!--      <el-table-column label="乙方银行账号" align="center" prop="sellerAccountNumber" />-->
      <!--      <el-table-column label="乙方签署日期" align="center" prop="sellerSignDate" width="180">-->
      <!--        <template #default="scope">-->
      <!--          <span>{{ parseTime(scope.row.sellerSignDate, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="合同文件名字" align="center" prop="contractFileName" />-->
      <!--      <el-table-column label="合同文件路径" align="center" prop="contractFile" />-->
      <el-table-column label="备注" align="center" prop="remarks" width="80" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="140">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleReceivables(scope.row)"
            v-hasPermi="['scm:scmCustomerOrders:edit']">收款</el-button>
          <el-button link type="primary" icon="Edit" @click="handleInvoice(scope.row)"
            v-hasPermi="['scm:scmCustomerOrders:edit']">发票</el-button>
          <!--          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['scm:scmCustomerOrders:edit']">修改</el-button>-->
          <!--          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['scm:scmCustomerOrders:remove']">删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改客户订单对话框 开始-->
    <el-dialog :title="title" v-model="open" width="800px" append-to-body>
      <el-form ref="scmCustomerOrdersRef" :model="form" :rules="rules" label-width="90px" disabled>
        <!--        <el-form-item label="项目ID" prop="projectId">-->
        <!--          <el-input v-model="form.projectId" placeholder="请输入项目ID" />-->
        <!--        </el-form-item>-->
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="订单编号" prop="orderCode">
              <el-input v-model="form.orderCode" placeholder="请输入订单编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订单日期" prop="orderDate">
              <el-date-picker clearable v-model="form.orderDate" type="date" value-format="YYYY-MM-DD"
                placeholder="请选择订单日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="客户名称" prop="buyerTitle">
          <el-input v-model="form.buyerTitle" placeholder="请输入甲方抬头" />
        </el-form-item>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="订单到货日" prop="requestedDeliveryDate">
              <el-date-picker clearable v-model="form.requestedDeliveryDate" type="date" value-format="YYYY-MM-DD"
                placeholder="请选择订单到货日">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="到货日回复" prop="repliedDeliveryDate">
              <el-date-picker clearable v-model="form.repliedDeliveryDate" type="date" value-format="YYYY-MM-DD"
                placeholder="请选择到货日回复">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item label="订单总金额" prop="totalAmount">
              <el-input v-model="form.totalAmount" placeholder="请输入订单总金额" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="已收款金额" prop="receivedAmount">
              <el-input v-model="form.receivedAmount" placeholder="请输入已收款金额" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发票金额" prop="invoiceAmount">
              <el-input v-model="form.invoiceAmount" placeholder="请输入发票金额" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
          </el-col>
          <el-col :span="12">
          </el-col>
        </el-row>






        <el-form-item label="支付状态" prop="paymentStatus">
          <el-select v-model="form.paymentStatus" placeholder="请选择支付状态">
            <el-option v-for="dict in scm_payment_status" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>

        <!--        <el-form-item label="甲方地址" prop="buyerAddress">-->
        <!--          <el-input v-model="form.buyerAddress" placeholder="请输入甲方地址" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="甲方联系人" prop="buyerPerson">-->
        <!--          <el-input v-model="form.buyerPerson" placeholder="请输入甲方联系人" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="甲方电话" prop="buyerPhone">-->
        <!--          <el-input v-model="form.buyerPhone" placeholder="请输入甲方电话" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="甲方开户银行" prop="buyerAccountBank">-->
        <!--          <el-input v-model="form.buyerAccountBank" placeholder="请输入甲方开户银行" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="甲方银行账号" prop="buyerAccountNumber">-->
        <!--          <el-input v-model="form.buyerAccountNumber" placeholder="请输入甲方银行账号" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="甲方签署日期" prop="buyerSignDate">-->
        <!--          <el-date-picker clearable v-model="form.buyerSignDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择甲方签署日期">-->
        <!--          </el-date-picker>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="乙方抬头" prop="sellerTitle">-->
        <!--          <el-input v-model="form.sellerTitle" placeholder="请输入乙方抬头" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="乙方地址" prop="sellerAddress">-->
        <!--          <el-input v-model="form.sellerAddress" placeholder="请输入乙方地址" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="乙方联系人" prop="sellerPerson">-->
        <!--          <el-input v-model="form.sellerPerson" placeholder="请输入乙方联系人" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="乙方电话" prop="sellerPhone">-->
        <!--          <el-input v-model="form.sellerPhone" placeholder="请输入乙方电话" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="乙方开户银行" prop="sellerAccountBank">-->
        <!--          <el-input v-model="form.sellerAccountBank" placeholder="请输入乙方开户银行" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="乙方银行账号" prop="sellerAccountNumber">-->
        <!--          <el-input v-model="form.sellerAccountNumber" placeholder="请输入乙方银行账号" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="乙方签署日期" prop="sellerSignDate">-->
        <!--          <el-date-picker clearable v-model="form.sellerSignDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择乙方签署日期">-->
        <!--          </el-date-picker>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="合同文件名字" prop="contractFileName">-->
        <!--          <el-input v-model="form.contractFileName" placeholder="请输入合同文件名字" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="合同文件路径" prop="contractFile">-->
        <!--          <file-upload v-model="form.contractFile"/>-->
        <!--        </el-form-item>-->
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-divider content-position="center">客户订单明细信息</el-divider>
        <!--        <el-row :gutter="10" class="mb8">-->
        <!--          <el-col :span="1.5">-->
        <!--            <el-button type="primary" icon="Plus" @click="handleAddScmCustomerOrderItems">添加</el-button>-->
        <!--          </el-col>-->
        <!--          <el-col :span="1.5">-->
        <!--            <el-button type="danger" icon="Delete" @click="handleDeleteScmCustomerOrderItems">删除</el-button>-->
        <!--          </el-col>-->
        <!--        </el-row>-->
        <el-table :data="scmCustomerOrderItemsList" :row-class-name="rowScmCustomerOrderItemsIndex"
          @selection-change="handleScmCustomerOrderItemsSelectionChange" ref="scmCustomerOrderItems">
          <!--          <el-table-column type="selection" width="50" align="center" />-->
          <el-table-column label="序号" align="center" prop="index" width="50" fixed />
          <el-table-column label="图号" align="center" prop="scmProjectProducts.drawingNumber" fixed width="100" />
          <!--          <el-table-column label="版本" align="center" prop="scmProjectProducts.version"  />-->
          <!--          <el-table-column label="内版本" align="center" prop="scmProjectProducts.internalVersion"  />-->
          <el-table-column label="品名" align="center" prop="scmProjectProducts.productName" />
          <!--          <el-table-column label="材质" align="center" prop="scmProjectProducts.material"  />-->
          <!--          <el-table-column label="规格" align="center" prop="scmProjectProducts.specification"  />-->
          <!--          <el-table-column label="颜色" align="center" prop="scmProjectProducts.color" />-->

          <el-table-column label="单价" prop="unitPrice" width="80" />
          <el-table-column label="数量" prop="quantity" width="80" />
          <el-table-column label="金额" prop="amount" width="80" />
          <el-table-column label="模具费" prop="moldCost" width="80" />
          <el-table-column label="工装费" prop="jigCost" width="80" />
          <!--          <el-table-column label="订单到货日" prop="requestedDeliveryDate" width="240">-->
          <!--            <template #default="scope">-->
          <!--              <el-date-picker clearable v-model="scope.row.requestedDeliveryDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择订单到货日">-->
          <!--              </el-date-picker>-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <!--          <el-table-column label="到货日回复" prop="repliedDeliveryDate" width="240">-->
          <!--            <template #default="scope">-->
          <!--              <el-date-picker clearable v-model="scope.row.repliedDeliveryDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择到货日回复">-->
          <!--              </el-date-picker>-->
          <!--            </template>-->
          <!--          </el-table-column>-->
        </el-table>

        <!--        <el-divider content-position="center">发票明细信息</el-divider>-->


        <!--        <el-divider content-position="center">收款明细信息</el-divider>-->

      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <!--          <el-button type="primary" @click="submitForm">确 定</el-button>-->
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 添加或修改客户订单对话框 结束-->

    <!-- 收款弹窗 开始 -->
    <el-dialog title="收款" v-model="openForReceivables" width="500px" append-to-body>
      <el-form ref="scmOrderReceivablesRef" :model="formForReceivables" :rules="rulesForReceivables" label-width="80px">
        <el-form-item label="订单编号" prop="orderCode">
          <el-input v-model="formForReceivables.orderCode" placeholder="请输入订单编号" disabled />
        </el-form-item>
        <el-form-item label="客户" prop="customerId">
          <el-input v-model="formForReceivables.customerId" placeholder="请输入客户ID" disabled />
        </el-form-item>
        <el-form-item label="回款金额" prop="money">
          <template #default="scope">
            <span style="margin-right: 4px;">¥</span>
            <el-input-number v-model="formForReceivables.money" placeholder="请输入回款金额" style="width: 54%;" :min="0"
              :controls="false" :precision="2" class="number-right" />
          </template>
        </el-form-item>
        <el-form-item label="回款日期" prop="returnDate">
          <el-date-picker clearable v-model="formForReceivables.returnDate" type="date" value-format="YYYY-MM-DD"
            placeholder="请选择回款日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="收款方式" prop="payType">
          <el-select v-model="formForReceivables.payType" placeholder="请选择">
            <el-option v-for="dict in scm_pay_type" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <!--        <el-form-item label="状态" prop="checkStatus">-->
        <!--          <el-select v-model="formForReceivables.checkStatus" placeholder="请选择">-->
        <!--            <el-option v-for="dict in scm_check_status" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"-->
        <!--            ></el-option>-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->

        <!--        <el-form-item label="回款编号" prop="number">-->
        <!--          <el-input v-model="form.number" placeholder="请输入回款编号" />-->
        <!--        </el-form-item>-->

        <!--        <el-form-item label="订单ID" prop="orderId">-->
        <!--          <el-input v-model="form.orderId" placeholder="请输入订单ID" />-->
        <!--        </el-form-item>-->




        <!--        <el-form-item label="审批人" prop="checkAdminId">-->
        <!--          <el-input v-model="form.checkAdminId" placeholder="请输入" />-->
        <!--        </el-form-item>-->
        <el-form-item label="备注" prop="remark">
          <el-input v-model="formForReceivables.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <!--        <el-form-item label="负责人ID" prop="ownerUserId">-->
        <!--          <el-input v-model="form.ownerUserId" placeholder="请输入负责人ID" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="负责人" prop="ownerUserName">-->
        <!--          <el-input v-model="formForReceivables.ownerUserName" placeholder="请输入负责人" />-->
        <!--        </el-form-item>-->

      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitFormForReceivables">确 定</el-button>
          <el-button @click="cancelForReceivables">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <!--    收款弹窗结束-->

    <!-- 改发票对话框 开始-->
    <el-dialog :title="titleForInvoice" v-model="openForInvoice" width="500px" append-to-body>
      <el-form ref="scmInvoiceRef" :model="formForInvoice" :rules="rulesForInvoice" label-width="80px">
        <!--        <el-form-item label="订单ID" prop="orderId">-->
        <!--          <el-input v-model="formForInvoice.orderId" placeholder="请输入订单ID" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="订单类型" prop="orderType">-->
        <!--          <el-radio-group v-model="formForInvoice.orderType">-->
        <!--            <el-radio-->
        <!--                v-for="dict in scm_invoice_order_type"-->
        <!--                :key="dict.value"-->
        <!--                :label="parseInt(dict.value)"-->
        <!--            >{{dict.label}}</el-radio>-->
        <!--          </el-radio-group>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="客户供应商ID" prop="customerSupplierId">-->
        <!--          <el-input v-model="formForInvoice.customerSupplierId" placeholder="请输入客户供应商ID" />-->
        <!--        </el-form-item>-->
        <el-form-item label="客户名称" prop="customerName">
          <el-input v-model="formForInvoice.customerName" placeholder="" disabled />
        </el-form-item>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="发票类型" prop="invoiceType">
              <el-radio-group v-model="formForInvoice.invoiceType">
                <el-radio v-for="dict in scm_invoice_type" :key="dict.value"
                  :label="parseInt(dict.value)">{{ dict.label }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发票日期" prop="invoiceDate">
              <el-date-picker v-model="formForInvoice.invoiceDate" type="date" placeholder="选择发票日期" style="width: 100%"
                value-format="yyyy-MM-dd"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="税前金额" prop="moneyIncludeTax">
              <el-input-number v-model="formForInvoice.moneyIncludeTax" placeholder="请输入税前金额" :min="0"
                style="width: 100%;" :controls="false" class="number-right" :precision="2"
                @change="handleMoneyIncludeTaxChange" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="税后金额" prop="moneyExcludeTax">
              <el-input-number v-model="formForInvoice.moneyExcludeTax" placeholder="请输入税后金额" :min="0"
                style="width: 100%;" :controls="false" class="number-right" :precision="2" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="税率(%)" prop="taxRate">
              <el-input-number v-model="formForInvoice.taxRate" placeholder="请输入税率" :min="0" style="width: 100%;"
                :controls="false" class="number-right" @change="handleTaxRateChange" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="税收金额" prop="moneyOfTax">
              <el-input-number v-model="formForInvoice.moneyOfTax" placeholder="请输入税收金额" :min="0" style="width: 100%;"
                :controls="false" class="number-right" :precision="2" disabled />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="备注" prop="remarks">
          <el-input v-model="formForInvoice.remarks" placeholder="请输入备注" type="textarea" :rows="3" />
        </el-form-item>
        <!--        <el-form-item label="发票附件" prop="attachmentUrl">-->
        <!--          <el-input v-model="formForInvoice.attachmentUrl" placeholder="请输入发票附件" />-->
        <!--        </el-form-item>-->

        <!--        <el-form-item label="状态" prop="status">-->
        <!--          <el-select v-model="formForInvoice.status" placeholder="请选择状态">-->
        <!--            <el-option-->
        <!--                v-for="dict in scm_invoice_status"-->
        <!--                :key="dict.value"-->
        <!--                :label="dict.label"-->
        <!--                :value="parseInt(dict.value)"-->
        <!--            ></el-option>-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitFormForInvoice">确 定</el-button>
          <el-button @click="cancelForInvoice">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 改发票对话框 结束-->

  </div>
</template>

<script setup name="ScmCustomerOrders">
import { listScmCustomerOrders, getScmCustomerOrders, delScmCustomerOrders, addScmCustomerOrders, updateScmCustomerOrders } from "@/api/scm/scmCustomerOrders";
import {addScmOrderReceivables, updateScmOrderReceivables, delScmOrderReceivables} from "@/api/scm/scmOrderReceivables.js";
import {addScmInvoice, updateScmInvoice, delScmInvoice} from "@/api/scm/scmInvoice.js";

const { proxy } = getCurrentInstance();
const { scm_payment_status } = proxy.useDict('scm_payment_status');

const scmCustomerOrdersList = ref([]);
const scmCustomerOrderItemsList = ref([]);
const open = ref(false);
const openForReceivables = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const checkedScmCustomerOrderItems = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  formForReceivables: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    projectId: null,
    orderCode: null,
    orderDate: null,
    requestedDeliveryDate: null,
    repliedDeliveryDate: null,
    paymentStatus: null,
  },
  rules: {
    projectId: [
      { required: true, message: "项目ID不能为空", trigger: "blur" }
    ],
    orderCode: [
      { required: true, message: "订单编号不能为空", trigger: "blur" }
    ],
  },
  rulesForReceivables: {}
});

const { queryParams, form, rules, formForReceivables, rulesForReceivables } = toRefs(data);

/** 查询客户订单列表 */
function getList() {
  loading.value = true;
  listScmCustomerOrders(queryParams.value).then(response => {
    scmCustomerOrdersList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    projectId: null,
    orderCode: null,
    orderDate: null,
    requestedDeliveryDate: null,
    repliedDeliveryDate: null,
    totalAmount: null,
    receivedAmount: null,
    invoiceAmount: null,
    paymentStatus: null,
    buyerTitle: null,
    buyerAddress: null,
    buyerPerson: null,
    buyerPhone: null,
    buyerAccountBank: null,
    buyerAccountNumber: null,
    buyerSignDate: null,
    sellerTitle: null,
    sellerAddress: null,
    sellerPerson: null,
    sellerPhone: null,
    sellerAccountBank: null,
    sellerAccountNumber: null,
    sellerSignDate: null,
    contractFileName: null,
    contractFile: null,
    remarks: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null
  };
  scmCustomerOrderItemsList.value = [];
  proxy.resetForm("scmCustomerOrdersRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加客户订单";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getScmCustomerOrders(_id).then(response => {
    form.value = response.data;
    scmCustomerOrderItemsList.value = response.data.scmCustomerOrderItemsList;
    open.value = true;
    title.value = "修改客户订单";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["scmCustomerOrdersRef"].validate(valid => {
    if (valid) {
      form.value.scmCustomerOrderItemsList = scmCustomerOrderItemsList.value;
      if (form.value.id != null) {
        updateScmCustomerOrders(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addScmCustomerOrders(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除客户订单编号为"' + _ids + '"的数据项？').then(function() {
    return delScmCustomerOrders(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 客户订单明细序号 */
function rowScmCustomerOrderItemsIndex({ row, rowIndex }) {
  row.index = rowIndex + 1;
}

/** 客户订单明细添加按钮操作 */
function handleAddScmCustomerOrderItems() {
  let obj = {};
  obj.productId = "";
  obj.purchaseCategory = "";
  obj.demandType = "";
  obj.model = "";
  obj.manufactureNumber = "";
  obj.manufactureSubNumber = "";
  obj.drawingNumberModel = "";
  obj.drawingVersion = "";
  obj.productName = "";
  obj.material = "";
  obj.size = "";
  obj.specification = "";
  obj.color = "";
  obj.unitPriceType = "";
  obj.unitPrice = "";
  obj.quantity = "";
  obj.amount = "";
  obj.moldCost = "";
  obj.jigCost = "";
  obj.requestedDeliveryDate = "";
  obj.repliedDeliveryDate = "";
  obj.remarks = "";
  scmCustomerOrderItemsList.value.push(obj);
}

/** 客户订单明细删除按钮操作 */
function handleDeleteScmCustomerOrderItems() {
  if (checkedScmCustomerOrderItems.value.length == 0) {
    proxy.$modal.msgError("请先选择要删除的客户订单明细数据");
  } else {
    const scmCustomerOrderItemss = scmCustomerOrderItemsList.value;
    const checkedScmCustomerOrderItemss = checkedScmCustomerOrderItems.value;
    scmCustomerOrderItemsList.value = scmCustomerOrderItemss.filter(function(item) {
      return checkedScmCustomerOrderItemss.indexOf(item.index) == -1
    });
  }
}

/** 复选框选中数据 */
function handleScmCustomerOrderItemsSelectionChange(selection) {
  checkedScmCustomerOrderItems.value = selection.map(item => item.index)
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('scm/scmCustomerOrders/export', {
    ...queryParams.value
  }, `scmCustomerOrders_${new Date().getTime()}.xlsx`)
}

// 在<script setup>中添加
function handleOrderCodeClick(row) {
  // 重置表单
  reset();

  // 加载选中行的数据
  getScmCustomerOrders(row.id).then(response => {
    form.value = response.data;
    scmCustomerOrderItemsList.value = response.data.scmCustomerOrderItemsList;
    open.value = true;
    title.value = "查看客户订单详情";
  });
}

// 添加需要的导入
import { listScmOrderReceivables } from "@/api/scm/scmOrderReceivables.js";
import { listScmInvoice } from "@/api/scm/scmInvoice.js";
// 在文件顶部添加 nextTick 导入
import { nextTick } from 'vue';

// 添加响应式数据
const activeTabName = ref('receivables');
const receivablesData = ref({});
const invoiceData = ref({});
const receivablesLoading = ref({});
const invoiceLoading = ref({});
const expandedRows = ref([]);// 存储当前展开的行
const expandRowKeys = ref([]); // 控制展开行的key

// 处理标签页切换
function handleTabChange(row) {
  // if (activeTabName.value === 'receivables' && !receivablesData.value[row.id]) {
  if (activeTabName.value === 'receivables') {
    loadReceivablesData(row.id);
  // } else if (activeTabName.value === 'invoice' && !invoiceData.value[row.id]) {
  } else if (activeTabName.value === 'invoice') {
    loadInvoiceData(row.id);
  }
}


// // 处理展开行变化
// function handleExpandChange(expandedRow, expandedRowsList) {
//   // 更新展开行列表
//   expandedRows.value = expandedRowsList;
//
//   // 如果有展开的行，加载第一个展开行的数据
//   if (expandedRowsList.length > 0) {
//     const firstExpandedRow = expandedRowsList[0];
//     // 延迟一点执行，确保展开动画完成
//     nextTick(() => {
//       handleTabChange(firstExpandedRow);
//     });
//   }
// }
// 处理展开行变化 + 如果已经给有别的行被展开，则关闭老的行
function handleExpandChange(expandedRow, expandedRowsList) {
  currentRow.value = expandedRow;
  // 如果有展开的行，只保留当前展开的行，关闭其他行
  if (expandedRowsList.length > 0) {
    // 只保留最新展开的行
    const latestExpandedRow = expandedRowsList[expandedRowsList.length - 1];
    expandRowKeys.value = [latestExpandedRow.id];
    expandedRows.value = [latestExpandedRow];

    // 延迟一点执行，确保展开动画完成
    nextTick(() => {
      handleTabChange(latestExpandedRow);
    });
  } else {
    // 如果没有展开的行，清空展开行记录
    expandRowKeys.value = [];
    expandedRows.value = [];
  }
}

// 加载收款信息
function loadReceivablesData(orderId) {
  // 设置加载状态
  receivablesLoading.value[orderId] = true;

  // 查询收款信息
  listScmOrderReceivables({ orderId: orderId }).then(response => {
    receivablesData.value[orderId] = response.rows || response.data || [];
    receivablesLoading.value[orderId] = false;
  }).catch(() => {
    receivablesData.value[orderId] = [];
    receivablesLoading.value[orderId] = false;
  });
}

// 加载发票信息
function loadInvoiceData(orderId) {
  // 设置加载状态
  invoiceLoading.value[orderId] = true;

  // 查询发票信息
  listScmInvoice({ orderId: orderId }).then(response => {
    invoiceData.value[orderId] = response.rows || response.data || [];
    invoiceLoading.value[orderId] = false;
  }).catch(() => {
    invoiceData.value[orderId] = [];
    invoiceLoading.value[orderId] = false;
  });
}

getList();


//收款表单 开始
const { scm_pay_type, scm_check_status } = proxy.useDict('scm_pay_type', 'scm_check_status');
// 收款表单重置
function resetForReceivables() {
  formForReceivables.value = {
    id: null,
    number: null,
    customerId: null,
    orderId: null,
    orderCode: null,
    returnDate: null,
    money: null,
    checkStatus: 1,
    checkAdminId: null,
    remark: null,
    ownerUserId: null,
    ownerUserName: null,
    payType: 2,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null
  };
  proxy.resetForm("scmOrderReceivablesRef");
}
const currentRow = ref(null);
/** 收款按钮操作 */
function handleReceivables(row) {
  resetForReceivables();
  formForReceivables.value.projectId = row.projectId;
  formForReceivables.value.orderId = row.id;
  formForReceivables.value.orderCode = row.orderCode;
  formForReceivables.value.returnDate = proxy.parseTime(new Date(), '{y}-{m}-{d}');
  openForReceivables.value = true;
  // currentRow.value = row; // 设置当前行
  // const _id = row.id || ids.value

}
// 取消按钮
function cancelForReceivables() {
  openForReceivables.value = false;
  resetForReceivables();
}
/** 提交按钮 */
function submitFormForReceivables() {
  proxy.$refs["scmOrderReceivablesRef"].validate(valid => {
    if (valid) {
      if (formForReceivables.value.id != null) {
        updateScmOrderReceivables(formForReceivables.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          openForReceivables.value = false;
          // 检查该行是否已展开，如果已展开则刷新收款明细
          if (currentRow.value ) {
            // 清除缓存的收款数据，重新加载
            delete receivablesData.value[currentRow.value.id];
            loadReceivablesData(currentRow.value.id);
          }
          getList();
        });
      } else {
        addScmOrderReceivables(formForReceivables.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          openForReceivables.value = false;
          // 检查该行是否已展开，如果已展开则刷新收款明细
          if (currentRow.value && expandedRows.value.includes(currentRow.value)) {
            // 清除缓存的收款数据，重新加载
            delete receivablesData.value[currentRow.value.id];
            loadReceivablesData(currentRow.value.id);
          }
          getList();
        });
      }
    }
  });
}

// 修改收款记录
function handleUpdateReceivables(row) {
  resetForReceivables();
  Object.assign(formForReceivables.value, row);
  openForReceivables.value = true;
  // currentRow.value = row; // 设置当前行
}

// 删除收款记录
function handleDeleteReceivables(row) {
  proxy.$modal.confirm('是否确认删除收款记录？').then(() => {
    return delScmOrderReceivables(row.id);
  }).then(() => {
    // 检查该行是否已展开，如果已展开则刷新收款明细
    if (currentRow.value ) {
      // 清除缓存的收款数据，重新加载
      delete receivablesData.value[currentRow.value.id];
      loadReceivablesData(currentRow.value.id);
    }
    proxy.$modal.msgSuccess("删除成功");
    getList();
  }).catch(() => {});
}

// 发票表单 开始
const { scm_invoice_order_type, scm_invoice_type, scm_invoice_status } = proxy.useDict('scm_invoice_order_type', 'scm_invoice_type', 'scm_invoice_status');
const dataForInvoice = reactive({
  formForInvoice: {},
  queryParamsForInvoice: {
    pageNum: 1,
    pageSize: 10,
    orderId: null,
    orderType: null,
    customerSupplierId: null,
    invoiceType: null,
    invoiceDate: null,
    checkStatus: null,
    status: null,
  },
  rulesForInvoice: {
    orderId: [
      { required: true, message: "订单ID不能为空", trigger: "blur" }
    ],
    orderType: [
      { required: true, message: "订单类型不能为空", trigger: "change" }
    ],
    customerSupplierId: [
      { required: true, message: "客户供应商ID不能为空", trigger: "blur" }
    ],
    invoiceType: [
      { required: true, message: "发票类型不能为空", trigger: "change" }
    ],
    taxRate: [
      { required: true, message: "税率不能为空", trigger: "blur" }
    ],
  }
});

const { queryParamsForInvoice, formForInvoice, rulesForInvoice } = toRefs(dataForInvoice);
const openForInvoice = ref(false);
const titleForInvoice = ref("");
// 格式化当前日期
function formatCurrentDate() {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0');
  const day = String(now.getDate()).padStart(2, '0');
  return `${year}-${month}-${day}`;
}

// 收款表单重置
function resetForInvoice() {
  formForInvoice.value = {
    id: null,
    orderId: null,
    orderType: 1,
    customerSupplierId: null,
    customerName: null,
    invoiceType: 2,
    invoiceDate: formatCurrentDate(),
    moneyIncludeTax: null,
    moneyExcludeTax: 0,
    moneyOfTax: 0,
    taxRate: 13,
    remarks: null,
    attachmentUrl: null,
    checkStatus: null,
    status: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null
  };
  proxy.resetForm("scmOrderReceivablesRef");
}
/** 发票按钮操作 */
function handleInvoice(row) {
  resetForInvoice();
  formForInvoice.value.orderId = row.id;
  formForInvoice.value.customerSupplierId = row.customerId;
  formForInvoice.value.customerName = row.buyerTitle;
  // formForInvoice.value.returnDate = proxy.parseTime(new Date(), '{y}-{m}-{d}');
  openForInvoice.value = true;
  titleForInvoice.value = "添加发票";
  // currentRow.value = row; // 设置当前行
  // const _id = row.id || ids.value

}
// 取消按钮
function cancelForInvoice() {
  openForInvoice.value = false;
  resetForInvoice();
}
/** 提交按钮 */
function submitFormForInvoice() {
  proxy.$refs["scmInvoiceRef"].validate(valid => {
    if (valid) {
      if (formForInvoice.value.id != null) {
        updateScmInvoice(formForInvoice.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          openForInvoice.value = false;
          // 检查该行是否已展开，如果已展开则刷新发票明细
          if (currentRow.value ) {
            // 清除缓存的发票数据，重新加载
            delete invoiceData.value[currentRow.value.id];
            loadInvoiceData(currentRow.value.id);
          }
          getList();
        });
      } else {
        addScmInvoice(formForInvoice.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          openForInvoice.value = false;
          // 检查该行是否已展开，如果已展开则刷新发票明细
          if (currentRow.value && expandedRows.value.includes(currentRow.value)) {
            // 清除缓存的发票数据，重新加载
            delete invoiceData.value[currentRow.value.id];
            loadInvoiceData(currentRow.value.id);
          }
          getList();
        });
      }
    }
  });
}

// 发票表单 税前金额改变时触发
function handleMoneyIncludeTaxChange(value) {
  // 如果需要计算税后金额和税收金额
  if (value !== null && formForInvoice.value.taxRate !== null) {
    // 计算税收金额
    const taxAmount = value * (formForInvoice.value.taxRate / 100);
    formForInvoice.value.moneyOfTax = Number(taxAmount.toFixed(2));

    // 计算税后金额
    formForInvoice.value.moneyExcludeTax = Number((value - taxAmount).toFixed(2));
  }
}
// 发票表单 税率改变时触发
function handleTaxRateChange(value) {
  // 如果需要计算税后金额和税收金额
  if (value !== null && formForInvoice.value.moneyIncludeTax !== null) {
    // 计算税收金额
    const taxAmount = formForInvoice.value.moneyIncludeTax * (value / 100);
    formForInvoice.value.moneyOfTax = Number(taxAmount.toFixed(2));

    // 计算税后金额
    formForInvoice.value.moneyExcludeTax = Number((formForInvoice.value.moneyIncludeTax - taxAmount).toFixed(2));
  }
}

// 修改发票记录
function handleUpdateInvoice(row) {
  resetForInvoice();
  Object.assign(formForInvoice.value, row);
  openForInvoice.value = true;
  titleForInvoice.value = "修改发票";
  // currentRow.value = row; // 设置当前行
}

// 删除发票记录
function handleDeleteInvoice(row) {
  proxy.$modal.confirm('是否确认删除发票记录？').then(() => {
    return delScmInvoice(row.id);
  }).then(() => {
    // 检查该行是否已展开，如果已展开则刷新发票明细
    if (currentRow.value ) {
      // 清除缓存的发票数据，重新加载
      delete invoiceData.value[currentRow.value.id];
      loadInvoiceData(currentRow.value.id);
    }
    proxy.$modal.msgSuccess("删除成功");
    getList();
  }).catch(() => {});
}


</script>

<style scoped>
/* 使用深度选择器确保 el-input-number 内容靠右对齐 */
:deep(.number-right .el-input__inner) {
  text-align: right !important;
}

/* 所有 el-input-number 内容靠右对齐 */
:deep(.el-input-number .el-input__inner) {
  width: 100%;
}
</style>